import { mapGetters, mapActions } from 'vuex'
import { clearLocalStorage } from '../utils/localStorage'
export const garbageMixin = {
  computed: {
    ...mapGetters([
      'userName',
      'userPassword',
      'userAge',
      'userImg',
      'userSex',
      'userPhone',
      'userId',
      'userIntergration',
      'userSessionId',
      'scanList',
      'scanImg'
    ])
  },
  methods: {
    ...mapActions([
      'setUserName',
      'setUserPassword',
      'setUserAge',
      'setUserImg',
      'setUserSex',
      'setUserPhone',
      'setUserId',
      'setUserIntergration',
      'setUserSessionId',
      'setScanList',
      'setScanImg'
    ])
  }
}
// document.addEventListener('visibilitychange', function () {
//   var isHidden = document.hidden
//   console.log(isHidden, 'isHidden')
//   if (isHidden) {
//     clearLocalStorage()
//   }
// })
window.onbeforeunload = function () {
  var n = window.event.screenX - window.screenLeft
  var b = n > document.documentElement.scrollWidth - 20
  // 页面关闭
  if (b && (window.event.clientY < 0 || window.event.altKey)) {
    clearLocalStorage()
    sessionStorage.clear()
  }
}
